package com.qf5.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;

@Component
@Aspect
public class DeleteAdvice {

    @Pointcut("execution(* com.qf5.service..*.delete(..))")
    public void pt(){}

    @Around("pt()")
    public Object deleteLog(ProceedingJoinPoint pjp) throws Throwable {

        Object proceed = pjp.proceed();

        //记录日志
        if (((int)proceed) != 0) {
            Integer userId = 1;
            Date oprTime = new Date();
            String methodSig = pjp.getSignature().toLongString();
            Object[] args = pjp.getArgs();

            //记录到数据库的日志表中
            System.out.println("-------------------" + userId + "=" + oprTime + "=" + methodSig + "=" + Arrays.toString(args));
        }
        return proceed;
    }
}
